var app = getApp()
Page({
    data: {
        openId: "",
        userInfo: {
            avatarUrl: '',
            nickName: '请登陆',
        },
        cartNum: 0,
        likeNum: 0,
        collectNum: 0,
        balance: 0,
        points: 0
    },

    onLoad: function () {
        const openId = wx.getStorageSync('openId')
        const nickName = wx.getStorageSync('name')
        const avatarUrl = wx.getStorageSync('avatarUrl')
        const cartNum = wx.getStorageSync('cart')["cartList"] ? wx.getStorageSync('cart')["cartList"].length : 0
        const likeNum = wx.getStorageSync('likeNum')
        const collectNum = wx.getStorageSync('collectNum')
        const balance = wx.getStorageSync('balance')
        const points = wx.getStorageSync('points')
        //更新数据
        this.setData({
            userInfo: {
                avatarUrl: avatarUrl,
                nickName: nickName
            },
            openId: openId,
            cartNum: cartNum,
            likeNum: likeNum,
            collectNum: collectNum,
            balance: balance,
            points: points
        })
    },

    toOrder() {
        wx.navigateTo({
            url: "../order/index"
        })
    },

    onShow() {
        this.onLoad()
    },

    reloadPage() {
        this.onLoad()
    },

    loginOut(e) {
        wx.clearStorageSync()
        this.reloadPage()
    },
})